package com.example.zuoye1;

import java.util.Collection;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
@@ -7,21 +8,25 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Collection;

@WebServlet(name = "ListCakeservlet",urlPatterns = "/ListCakeServlet")
@WebServlet(name = "ListCakeServlet", urlPatterns = "/ListCakeServlet")
public class ListCakeServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            resp.setContentType("text/html;charset=utf-8");
            PrintWriter out = resp.getWriter();
            Collection<Cake> cakes = CakeDB.getAll();
            out.write("本站提供的蛋糕有：<br>");

            out.println("<html>");
            out.println("<head><title>蛋糕列表</title></head>");
            out.println("<body>");
            out.println("本站提供的蛋糕有：<br>");
            for (Cake cake : cakes) {
                String url = "PurchaseServlet?id=" + cake.getId();
                out.write(cake.getName() + "<a href='" + url
                        + "'>点击购买</a><br>");
                out.println(cake.getName() + " - <a href='" + url + "'>点击购买</a><br>");
            }
            out.println("</body>");
            out.println("</html>");
            out.close();
        }
    }
\ No newline at end of file
}